﻿using AutoMapper;
using B.S.Sterilizationcenter.Domain.zmc;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Read.API.Appliaction.Commends.zmc;
using MediatR;
using SqlSugar;
using System.Collections.Generic;

namespace B.S.Sterilizationcenter.Read.API.Appliaction.CommandHandlers.zmc
{
    public class QueryApparatusTypeCommandHandlers : IRequestHandler<QueryApparatusTypeCommand, ApiResult<List<ApparatusType>>>

    {

        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;

        public QueryApparatusTypeCommandHandlers(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }

        /// <summary>
        /// 查询器械类型
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<List<ApparatusType>>> Handle(QueryApparatusTypeCommand request, CancellationToken cancellationToken)
        {
            try
            {
                ApiResult<List<ApparatusType>> result = new ApiResult<List<ApparatusType>>();
                var list = db.Queryable<ApparatusType>().ToList();
                result.Code = ApiEnums.查询成功;
                result.Msg = "查询成功";
                result.Data = list;
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
